const util = require("./util.js")
const config = require("./config.js")
const xxtea = require("./xxtea.js")
const Base64 = require("./base64.js")

/**
 * 审核开关:0
 */
function versionSwitch() {
	const inputData = buildVersionSwitch();
	return createHttpRequest(config.versionSwitch, inputData, true);
}

/**
 * 构建审核开关:1
 */
function buildVersionSwitch() {
	const normalData = {};
	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	util.log("buildVersionSwitch 0");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 小程序登录:1
 */
function wxAmpLogin(data) {
	const inputData = buildWxAmpLogin(data);
	return createHttpRequest(config.CMD_WX_AMP_LOGIN, inputData, true);
}

/**
 * 构建小程序登录:1
 */
function buildWxAmpLogin(data) {
	const normalData = {};
	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
		key: data.code,
		parentUserId: data.parentUserId,
	}

	util.log("buildWxAmpLogin 1");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}


/**
 * 获取用户基本信息:2
 */
function getUserInfo() {
	const inputData = buildGetUserInfo();
	return createHttpRequest(config.getUserInfo, inputData, true);
}

/**
 * 构建获取用户信息数据:2
 */
function buildGetUserInfo() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildGetUserInfo 2");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 签到 :3
 */
function sign() {
	const inputData = buildSign();
	return createHttpRequest(config.sign, inputData, true);
}

/**
 * 构建签到数据 :3
 */
function buildSign() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildSign 3");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 签到翻倍 4
 */
function signDouble() {
	const inputData = buildSignDouble();
	return createHttpRequest(config.signDouble, inputData, true);
}

/**
 * 构建签到翻倍数据:4
 */
function buildSignDouble(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildSignDouble 4");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 看视频领取音符 : 5
 */
function watchVideoGetNote() {
	const inputData = buildWatchVideoGetNote();
	return createHttpRequest(config.watchVideoGetNote, inputData, true);
}

/**
 * 构建看视频领取音符数据: 5
 */
function buildWatchVideoGetNote() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildWatchVideoGetNote 5");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 获取好友任务:6
 */
function friendTask() {
	const inputData = buildFriendTask();
	return createHttpRequest(config.friendTask, inputData, true);
}

/**
 * 构建获取好友任务数据:6
 */
function buildFriendTask() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}


	util.log("buildFriendTask 6");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 领取邀请任务音符：7
 */
function getInviteNote(data) {
	const inputData = buildGetInviteNote(data);
	return createHttpRequest(config.getInviteNote, inputData, true);
}

/**
 * 构建领取邀请任务音符数据：7
 */
function buildGetInviteNote(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.inviteTask = {
		userId: userId,
		id: data.id
	}

	util.log("buildGetInviteNote 7");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 点击双人擂台： 8
 */
function clickPK() {
	const inputData = buildClickPK();
	return createHttpRequest(config.clickPK, inputData, true);
}

/**
 * 构建点击双人擂台数据：8
 */
function buildClickPK() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildClickPK 8");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 匹配：9
 */
function matching() {
	const inputData = buildMatching();
	return createHttpRequest(config.matching, inputData, true);
}

/**
 * 构建匹配数据：9
 */
function buildMatching() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildMatching 9");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 获取擂台赛答题结果: 10
 */
function pkAnswer(data) {
	const inputData = buildPkAnswer(data);
	return createHttpRequestTen(config.pkAnswer, inputData);
}

/**
 * 构建获取擂台赛答题结果数据：10
 */
function buildPkAnswer(data) {
	const normalData = {}

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.songUser = {
		id: data.resultId,
		correctOption: data.correctOption,
	}

	util.log("buildPkAnswer 10");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 领取擂台赛奖励: 11
 */
function pkReward(data) {
	const inputData = buildPkReward(data);
	return createHttpRequest(config.pkReward, inputData, true);
}

/**
 * 构建领取擂台赛奖励数据：11
 */
function buildPkReward(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	// isGet, 是否双倍领取音符:0不是1是
	normalData.songUser = {
		userId: userId,
		isGet: data.isGet
	}

	util.log("buildPkReward 11");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 获取红包赛争夺赛页面：13
 */
function redbagSession() {
	const inputData = buildRedbagSession();
	return createHttpRequest(config.redbagSession, inputData, true);
}

/**
 * 构建红包赛争夺赛页面：13
 */
function buildRedbagSession() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildRedbagSession 13");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 红包争夺赛答题界面：14
 */
function competition(data) {
	const inputData = buildCompetition(data);
	return createHttpRequest(config.competition, inputData, true);
}

/**
 * 构建红包争夺赛答题界面：14
 */
function buildCompetition(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId,
		gameId: data.gameId
	}

	util.log("buildCompetition 14");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 红包赛答题结果: 15
 */
function competitionAnswer(data) {
	const inputData = buildCompetitionAnswer(data);
	return createHttpRequestTen(config.competitionAnswer, inputData);
}

/**
 * 构建红包赛答题结果：15
 */
function buildCompetitionAnswer(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	normalData.user = {
		userId: userId,
	}
//id 结果id correctOption 选择答案
	normalData.songUser = {
		id: data.resultId,
		correctOption: data.correctOption
	}

	util.log("buildCompetitionAnswer 15");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 领取红包赛奖励接口：16
 */
function competitionReward(data) {
	const inputData = buildCompetitionReward(data);
	return createHttpRequest(config.competitionReward, inputData, true);
}

/**
 * 构建领取红包赛奖励：16
 */
function buildCompetitionReward(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId,
		gameId: data.gameId
	}

	util.log("buildCompetitionReward 16");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}



/**
 * 红包争夺赛复活：17
 */
function competitionRevive(data) {
	const inputData = buildCompetitionRevive(data);
	return createHttpRequest(config.competitionRevive, inputData, true);
}

/**
 * 构建红包争夺赛复活：17
 */
function buildCompetitionRevive(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
//gameId 场次Id
	normalData.user = {
		userId: userId,
		gameId: data.gameId,
	}

	util.log("buildCompetitionRevive 17");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 获取砍价列表页面：18
 */
function discountList() {
	const inputData = buildDiscountList();
	return createHttpRequest(config.discountList, inputData, true);
}

/**
 * 构建获取砍价列表页面：18
 */
function buildDiscountList() {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.user = {
		userId: userId
	}

	util.log("buildDiscountList 18");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 发起砍价：19
 */
function startBargain(data) {
	const inputData = buildStartBargain(data);
	return createHttpRequest(config.startBargain, inputData, true);
}

/**
 * 构建发起砍价：19
 */
function buildStartBargain(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	//场次id bargainId
	normalData.userBargain = {
		userId: userId,
		bargainId: data.bargainId
	}

	util.log("buildStartBargain 19");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 进入砍价页面：20
 */
function myDiscount(data) {
	const inputData = buildMyDiscount(data);
	return createHttpRequest(config.myDiscount, inputData, true);
}

/**
 * 构建进入砍价页面：20
 */
function buildMyDiscount(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	//场次id bargainId
	normalData.userBargain = {
		userId: userId,
		bargainId: data.bargainId
	}


	util.log("buildMyDiscount 20");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 看视屏砍价：21
 */
function videoBargain(data) {
	const inputData = buildVideoBargain(data);
	return createHttpRequest(config.videoBargain, inputData, true);
}

/**
 * 构建看视屏砍价：21
 */
function buildVideoBargain(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	//场次id bargainId
	normalData.userBargain = {
		userId: userId,
		bargainId: data.bargainId
	}

	util.log("buildVideoBargain 21");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 帮忙砍价：22
 */
function helpBargain(data) {
	const inputData = buildhelpBargain(data);
	return createHttpRequest(config.helpBargain, inputData, true);
}

/**
 * 构建帮忙砍价：22
 */
function buildhelpBargain(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	//场次id bargainId
	normalData.userBargain = {
		userId: data.userId,
		bargainId: data.bargainId,
		helpUserId: userId
	}

	util.log("buildhelpBargain 22");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 领取砍价奖励: 23
 */
function bargainReward(data) {
	const inputData = buildBargainReward(data);
	return createHttpRequest(config.bargainReward, inputData, true);
}

/**
 * 构建领取砍价奖励：23
 */
function buildBargainReward(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	//场次id bargainId
	normalData.userBargain = {
		userId: userId,
		bargainId: data.bargainId
	}

	util.log("buildBargainReward 23");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 获取排行榜: 24
 */
function getRank(data) {
	const inputData = buildgetRank(data);
	return createHttpRequest(config.getRank, inputData, true);
}

/**
 * 构建获取排行榜: 24
 */
function buildgetRank(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	//rankType 排行榜类型0红包榜1对战榜
	normalData.user = {
		userId: userId,
		rankType: data.rankType
	}

	util.log("buildgetRank 24");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 获取提现列表信息: 25
 */
function withdrawList() {
	const inputData = buildWithdrawList();
	return createHttpRequest(config.withdrawList, inputData, true);
}

/**
 * 构建获取提现列表: 25
 */
function buildWithdrawList(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	normalData.user = {
		userId: userId
	}

	util.log("buildWithdrawList 25");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 获取提现: 26
 */
function withdraw(data) {
	const inputData = buildWithdraw(data);
	return createHttpRequest(config.withdraw, inputData, true);
}

/**
 * 构建提现信息: 26
 */
function buildWithdraw(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	normalData.extract = {
		userId: userId,
		money: data.money
	}

	util.log("buildWithdraw 26");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 预约比赛: 27
 */
function orderGame(data) {
	const inputData = buildOrderGame(data);
	return createHttpRequest(config.orderGame, inputData, true);
}

/**
 * 构建预约比赛: 27
 */
function buildOrderGame(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}
	normalData.user = {
		userId: userId,
		gameId: data.gameId
	}

	util.log("buildOrderGame 27");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 用户授权: 28
 */
function authorization(data) {
	const inputData = buildAuthorization(data);
	return createHttpRequest(config.authorization, inputData, true);
}

/**
 * 用户授权: 28
 */
function buildAuthorization(data) {
	const normalData = {}

	const jsonStr = {
		appId: config.CLIENT_APPID,
		code: data.code,
		iv: data.iv,
		encryptedData: data.encryptedData
	}

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
		jsonStr: jsonStr,
	}


	util.log("buildAuthorization 28");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 小程序试玩奖励: 29
 */
function tryRewared(data) {
	const inputData = buildTryRewared(data);
	return createHttpRequest(config.tryRewared, inputData, true);
}

/**
 * 小程序试玩奖励: 29
 */
function buildTryRewared(data) {
	const normalData = {}
	const userId = getUserId()

	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION,
	}

	normalData.statAdvertising = {
		advertisingId: data.advertisingId,
		appId: data.appId,
		userId: userId
	}


	util.log("buildTryRewared 29");
	const str = _buildEncryptStr(normalData);
	util.log(str)
	return str;
}
/**
 * 小程序跳转: 6
 */
function miniTurn(data) {
	const inputData = buildMiniTurn(data);
	return createHttpRequestAD(config.miniTurn, inputData, true);
}

/**
 * 小程序跳转: 6
 */
function buildMiniTurn(data) {
	const normalData = {}



	normalData.deviceProperties = {
		appId: config.CLIENT_APPID,
		version: config.CLIENT_VERSION_AD,
	}
	normalData.user = {
		openId: data.openId
	}

	util.log("buildMiniTurn 6");
	const str = _ADbuildEncryptStr(normalData);
	util.log(str)
	return str;
}

/**
 * 获取userId
 */
function getUserId() {
	let userId = ""

	try {
		userId = wx.getStorageSync('userId')
	} catch (e) {}

	if (!userId) { //获取userId存Storage
		
	} else {
		return userId
	}
}

/**
 * 创建网络请求
 * @params
 */
const createHttpRequestTen = (url, data) => {

	return new Promise((resolve, reject) => {

		util.log("url:(" + url + ")");

		wx.request({
			url: url,
			data: data,
			header: {
				'content-type': 'application/json;charset=utf-8',
			},
			method: "POST",
			success: res => {
				util.log(res)
				if (!res) {
					const errMsg = "返回数据为空";
					reject(errMsg);
					_showErrMsg(errMsg)
					return false
				}

				let result = res.data
				result = _buildDecryptStr(result)

				if (result.resultCode === -999) {
					const errMsg = "服务器繁忙，稍后再试！";
					reject(errMsg);
					_showErrMsg(errMsg)
				} else if (result.resultCode === 0) {
					let data = result.data || ""
					if (data) {
						// data = JSON.parse(data)
						
					}
					util.log(data);
					resolve(data)
				} else {
					const errMsg = result.resultInfo;
					reject(errMsg);
					_showErrMsg(errMsg)
				}
			},
			fail: (e) => {
				util.log(e);
				reject(e);
			},
			complete: () => {
				
			}
		});
	});
}
/**
 * 创建网络请求
 * @params
 */
const createHttpRequest = (url, data, isloading, type) => {

	return new Promise((resolve, reject) => {
		if (isloading) {
			wx.showLoading({
				mask: true,
				title: "加载中..."
			});
		}

		util.log("url:(" + url + ")");

		wx.request({
			url: url,
			data: data,
			header: {
				'content-type': 'application/json;charset=utf-8',
			},
			method: type || "POST",
			success: res => {
				util.log(res)
				if (!res) {
					const errMsg = "返回数据为空";
					reject(errMsg);
					_showErrMsg(errMsg)
					return false
				}

				let result = res.data
				result = _buildDecryptStr(result)

				if (result.resultCode === -999) {
					const errMsg = "服务器繁忙，稍后再试！";
					reject(errMsg);
					_showErrMsg(errMsg)
				} else if (result.resultCode === 0) {
					let data = result.data || ""
					if (data) {
						// data = JSON.parse(data)
						
					}
					util.log(data);
					resolve(data)
				} else {
					const errMsg = result.resultInfo;
					reject(errMsg);
					_showErrMsg(errMsg)
				}
			},
			fail: (e) => {
				util.log(e);
				reject(e);
			},
			complete: () => {
				if (isloading) {
					wx.hideLoading();
				}
			}
		});
	});
}
/**
 * 创建网络请求
 * @params
 */
const createHttpRequestAD = (url, data, isloading, type) => {

	return new Promise((resolve, reject) => {
		if (isloading) {
			wx.showLoading({
				mask: true,
				title: "加载中..."
			});
		}

		util.log("url:(" + url + ")");

		wx.request({
			url: url,
			data: data,
			header: {
				'content-type': 'application/json;charset=utf-8',
			},
			method: type || "POST",
			success: res => {
				util.log(res)
				if (!res) {
					const errMsg = "返回数据为空";
					reject(errMsg);
					_showErrMsg(errMsg)
					return false
				}

				let result = res.data
				result = _ADbuildDecryptStr(result)

				if (result.resultCode === -999) {
					const errMsg = "服务器繁忙，稍后再试！";
					reject(errMsg);
					_showErrMsg(errMsg)
				} else if (result.resultCode === 0) {
					let data = result.data || ""
					if (data) {
						// data = JSON.parse(data)
						
					}
					util.log(data);
					resolve(data)
				} else {
					const errMsg = result.resultInfo;
					reject(errMsg);
					_showErrMsg(errMsg)
				}
			},
			fail: (e) => {
				util.log(e);
				reject(e);
			},
			complete: () => {
				if (isloading) {
					wx.hideLoading();
				}
			}
		});
	});
}

/**
 * 显示网络失败信息
 */
function _showErrMsg(reason) {
	util.log(reason);

	var errMsg = "网络请求失败，请检查网络连接";
	if (reason) {
		if (typeof reason === "string") {
			errMsg = reason;
		}
	}

	wx.showToast({
		title: errMsg,
		icon: "none",
		duration: 2000,
	})
}

/**
 * 加密发送数据
 */
function _buildEncryptStr(inputObj) {
	var str = JSON.stringify(inputObj);
	util.log("=====请求数据=====");
	util.log(str);
	// str = xxtea.utf16to8(str);
	var encodeStr = new Base64.Base64().encode(str);
	var encryptStr = xxtea.xxtea_encrypt(encodeStr,config.CLIENT_KEY)
	// str = xxtea.utf16to8(str);
	// var encryptStr = xxtea.xxtea_encrypt(str, config.CLIENT_KEY);
	// var encodeStr = new Base64.Base64().encode(encryptStr);
	return encryptStr;
}
/**
 * 广告加密发送数据
 */
function _ADbuildEncryptStr(inputObj) {
	var str = JSON.stringify(inputObj);
	util.log("=====请求数据=====");
	util.log(str);
	// str = xxtea.utf16to8(str);
	var encodeStr = new Base64.Base64().encode(str);
	var encryptStr = xxtea.xxtea_encrypt(encodeStr,config.CLIENT_KEY_AD)
	// str = xxtea.utf16to8(str);
	// var encryptStr = xxtea.xxtea_encrypt(str, config.CLIENT_KEY);
	// var encodeStr = new Base64.Base64().encode(encryptStr);
	return encryptStr;
}

/**
 * 解密发送数据
 */
function _ADbuildDecryptStr(inputStr) {
	var decodeStr = null;
	try {
		var str = xxtea.xxtea_decrypt(inputStr,config.CLIENT_KEY_AD);
		// decryptStr = xxtea.utf8to16(decryptStr);
		var decryptStr = new Base64.Base64().decode(str)
		

		// var str = new Base64.Base64().decode(inputStr);
		// var decryptStr = xxtea.xxtea_decrypt(str, config.CLIENT_KEY);
		// decryptStr = xxtea.utf8to16(decryptStr);
		util.log("=====响应数据=====");
		util.log(decryptStr);
		var decodeStr = JSON.parse(decryptStr);
	} catch (error) {
		util.log(error);
	}
	return decodeStr;
}
/**
 * 解密发送数据
 */
function _buildDecryptStr(inputStr) {
	var decodeStr = null;
	try {
		var str = xxtea.xxtea_decrypt(inputStr,config.CLIENT_KEY);
		// decryptStr = xxtea.utf8to16(decryptStr);
		var decryptStr = new Base64.Base64().decode(str)
		

		// var str = new Base64.Base64().decode(inputStr);
		// var decryptStr = xxtea.xxtea_decrypt(str, config.CLIENT_KEY);
		// decryptStr = xxtea.utf8to16(decryptStr);
		util.log("=====响应数据=====");
		util.log(decryptStr);
		var decodeStr = JSON.parse(decryptStr);
	} catch (error) {
		util.log(error);
	}
	return decodeStr;
}



module.exports = {
	versionSwitch,
	wxAmpLogin,
	getUserId,
	getUserInfo,
	sign,
	signDouble,
	watchVideoGetNote,
	friendTask,
	getInviteNote,
	getRank,
	clickPK,
	matching,
	pkAnswer,
	pkReward,
	redbagSession,
	competition,
	competitionAnswer,
	competitionReward,
	competitionRevive,
	discountList,
	startBargain,
	myDiscount,
	videoBargain,
	helpBargain,
	bargainReward,
	withdrawList,
	withdraw,
	orderGame,
	authorization,
	tryRewared,
	miniTurn
}
